var vm = new Vue({
  el: '#portalMenu',
  mixins: [MIXINS.COMM],
  data: function () {
    var _that = this;
    var checkSame = function (rule, value, callback) {
      if (value === '') {
        callback(new Error('请再次输入密码'));
      } else if (value !== _that.editPasswordData.newPassword) {
        callback(new Error('两次输入密码不一致！'));
      } else {
        callback();
      }
    };
    var checkOldPass = function (rule, value, callback) {
      if (value === '') {
        callback(new Error('请输入原密码'));
      } else {
        request('opus-admin', {
          url: ctx + 'opus/front/om/users/passwordCheckout',
          data: { oldPassword: value },
          type: 'get'
        }, function (data) {
          if (data.success) {
            callback();
          } else {
            callback(new Error(data.message ? data.message : '原密码错误'));
          }
        })
      }
    };
    var checkDiffer = function (rule, value, callback) {

      //密码包含 数字,英文,字符中的两种以上，长度8-20
      var patrn = "^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)(?!([^(0-9a-zA-Z)])+$).{8,20}$";
      var re = new RegExp(patrn);
      if (value === '') {
        callback(new Error('请输入密码'));
      } else if (value == _that.editPasswordData.oldPassword) {
        callback(new Error('新密码和原密码不能相同！'));
      } else if (!re.test(value)) {
        callback(new Error('密码需含数字,英文,字符的两种，长度8-20'));
      } else {
        callback();
      }
    };
    return {
      ctx: ctx,
      headerData: [], // 头部菜单data
      headerDataShow: [], // 头部菜单展示data
      hideHeaderData: [], // 被隐藏的菜单
      headerActive: '', // 被选中的菜单项
      menuCount: 1, // 头部菜单展示条数 menuCount+1
      showMenuMore: false, // 是否展示更多菜单
      userSex: 0, // 用户性别
      userName: '超级管理员',
      activeTabIframe: '', // 顶部选项卡 绑定active
      activeTabData: [], // 顶部选项卡 所有展示的tab
      activeTabId: [], // 顶部选项卡 所有展示的tab id
      showTabOpt: false, // 右键tab展示
      tabOptTop: '',
      tabOptleft: '',
      curWidth: (document.documentElement.clientWidth || document.body.clientWidth), // 当前屏幕宽度
      curHeight: (document.documentElement.clientHeight || document.body.clientHeight), // 当前屏幕高度
      tabId: '',
      logoutSrc: [], // 退出登录列表
      portalTitle: null,
      todoMenuObj: {}, // 待办任务菜单数据
      todoMenuIndex: 0, // 待办菜单所在数组下标
      isFullScreen: true,
      msgIntervalTime: 180,
      needRequestQueue: [],
      intervalTimeStep: 1,// 间隔多少秒请求一个菜单红点数据
      portalLogoUrl: null,
      noticeCount: 0,
      orgList: [], // 用户所属部门可能多个
      fOrgInfo: {}, //
      loginName: '', // 用户登陆名
      userId: '',  // 用户id
      topOrgId: '',
      userEmail: '',
      userData: {}, // 用户详细信息
      forceHint: false, // 是否强制消息提醒
      messgeCount: 0,
      todoIndex: 0, // 待办消息当前index
      urgeIndex: 0, // 催办消息当前index
      todoMsgList: [], // 待办消息
      urgeMsgList: [], // 催办消息
      msgList: [], // 所有未读消息
      todoMsgIds: [], // 待办消息rangeId
      mainMsgIds: [], // 主办消息rangeId
      urgeMsgIds: [], // 催办消息rangeId
      mainMsgList: [], // 主办消息
      unmainMsgList: [], // 协办消息
      unmainIndex: 0, // 协办消息当前index
      TODOMENUTEXT: '待办任务', // 待办任务文本，用来匹配
      MAINMENUTEXT: '主办任务', // 主办任务文本，用来匹配
      editUserInfoFlag: false, // 是否展示个人信息topbar
      userInfoFlag: false,
      editPasswordFlag: false, // 是否展示修改密码弹窗
      editPasswordData: {
        oldPassword: '',
        newPassword: '',
        newPasswordCheck: ''
      }, // 修改密码data
      editPasswordRule: {
        oldPassword: [
          {validator: checkOldPass, required: true, trigger: 'blur'},
        ],
        newPassword: [
          {validator: checkDiffer, required: true, trigger: 'blur'}
        ],
        newPasswordCheck: [
          {validator: checkSame, required: true, trigger: 'blur'}
        ]
      },  // 修改密码校验
      userCommitsFlag: false,
      commentsList: [], // 个人常用意见
      logoutIframe: false, // 是否退出
      editAddTitle: '', //
      submitCommentsFlag2: false, //
      commentInfo: {},
      UNMAINMENUTEXT: '协办任务', // 协办任务文本，用来匹配
    }
  },
  watch: {
    forceHint: function (val) {
      localStorage.setItem('forceHint', val ? 1 : 0);
    },
  },
  mounted: function () {
    var _that = this;
    //在document挂载onlick事件
    document.addEventListener("click", this.displayMenuPopover)
    window.addEventListener("resize", function () {
      vm.curWidth = document.documentElement.clientWidth;
      vm.curHeight = document.documentElement.clientHeight;
      vm.setHeaderShow();
      if (!_that.checkFull()) {
        _that.isFullScreen = true;
      } else {
        _that.isFullScreen = false;
      }
    });
    // 监听子页面的传递过来的数据
    if (window.addEventListener) {
      window.addEventListener('message', _that.onMessage, false);
    } else {
      if (window.attachEvent) {
        window.attachEvent("onmessage", _that.onMessage);
      }
    }
    _that.getUserIndo(); // 获取用户登陆信息
    // 未读公告
    _that.getCountAoaMsgRangeForMyReceiveUnReaded();
    setInterval(function () {
      _that.getCountAoaMsgRangeForMyReceiveUnReaded();
    }, _that.msgIntervalTime * 1000);
    //获取门户标题及logo url
    _that.initPortal();
    window.setInterval(function () {
      if (_that.needRequestQueue&&_that.needRequestQueue.length > 0) {
        var _target = _that.needRequestQueue.shift();
        _that.getSingleMenuBadge(_target);
      }
    }, _that.intervalTimeStep * 1000);
  },
  methods: {
    // 获取个人常用意见
    getCommitsList: function () {
      var _that = this;
      _that.userCommitsFlag = true
      request('', {
        // url: 'http://106.52.77.101:8083/aplanmis-front/rest/comment/getAllActiveUserOpinions',
        url: ctx + 'rest/comment/getAllActiveUserOpinions',
        type: 'get'
      }, function (data) {
        if (data.success) {
          _that.commentsList = data.content;
        } else {
          _that.$message({
            message: data.message ? data.message : '获取个人意见失败',
            type: 'error'
          });
        }
      }, function (msg) {
        _that.$message({
          message: msg.message ? msg.message : '获取个人意见失败',
          type: 'error'
        });
      })
    },
    // 系统消息强提醒设置
    changeForceHint: function (val) {
      var vm = this;
      this.http({
        url: 'opus/front/om/user/info/enableOrDisableRemind.do',
        type: 'post',
        data: {userId: vm.userId},
        success: function () {
          if (val) {
            text = '消息强提醒已开启';
          } else {
            text = '已关闭消息强提醒';
          }
          vm.$message.success(text);
        },
        error: function (res) {
          vm.forceHint = !vm.forceHint;
          vm.$message.error(res.message || '操作失败');
        },
        fail: function () {
          vm.forceHint = !vm.forceHint;
          vm.$message.error('请求服务器失败');
        },
      });
    },
    // 退出登陆
    logout: function (e) {
      e.cancelBubble = true;
      var _that = this;
      confirmMsg('', '确定要退出登陆吗？', function () {
        _that.logoutIframe = true;
        _that.$nextTick(function () {
          setTimeout(function () {
            window.location.href = ctx + 'logout';
          }, 500);
        });
      }, function () {
        _that.logoutIframe = false;
      })
    },
    // 是否展示login-info
    showEditUserInfo: function () {
      this.editUserInfoFlag = !this.editUserInfoFlag;
    },
    // 清空表单
    clearDialogData: function (formName) {
      this.$refs[formName].resetFields();
    },
    // 编辑保存用户信息
    editUserInfoSubmit: function () {
      var _that = this;
      var param = {
        userName: _that.userData.userName,
        userCode: _that.userData.userCode,
        userId: _that.userData.userId,
        userFamilyAddress: _that.userData.userFamilyAddress,
        userDomicilePlace: _that.userData.userDomicilePlace,
        userMobile: _that.userData.userMobile,
        userEmail: _that.userData.userEmail,
        userPost: _that.userData.userPost,
        userAssignDate: _that.userData.userAssignDate,
        isRejectSms: _that.userData.isRejectSms
      }
      request('', {
        // url: 'http://192.168.30.37:8080/opus-front/'+'opus/front/om/user/info/saveUserInfo.do',
        url: ctx + 'opus/front/om/user/info/saveUserInfo.do',
        data: param,
        type: 'get'
      }, function (data) {
        if (data.success) {
          _that.$message({
            message: '保存成功',
            type: 'success'
          });
          _that.userInfoFlag = false;
        } else {
          _that.$message({
            message: data.message ? data.message : '保存失败',
            type: 'error'
          });
        }
      }, function (msg) {
        _that.$message({
          message: msg.message ? msg.message : '保存失败',
          type: 'error'
        });
      })
    },
    // 修改密码
    editPasswordSubmit: function () {
      var _that = this;
      _that.$refs['editPasswordData'].validate(function (valid) {
        if (valid) {
          var props = {
            newPassword: _that.editPasswordData.newPassword,
            oldPassword: _that.editPasswordData.oldPassword,
          };
          request('opus-admin', {
            url: ctx + 'opus/front/om/users/password',
            data: props,
            type: 'post'
          }, function (data) {
            if (data.success) {
              _that.$message({
                message: '密码修改成功',
                type: 'success'
              });
              _that.editPasswordFlag = false;
            } else {
              _that.$message({
                message: data.message ? data.message : '密码修改失败',
                type: 'error'
              });
            }
          }, function (msg) {
            _that.$message({
              message: msg.message ? msg.message : '密码修改失败',
              type: 'error'
            });
          })
        } else {
          alertMsg('', '请输入完整且正确的信息', '关闭', 'warning', true);
          return false;
        }
      });
    },


    // 新增 常用意见
    addCommit: function () {
      this.submitCommentsFlag2 = true;
      this.editAddTitle = '新增常用意见';
      this.commentInfo = {
        comment: '',
      };
      this.editCommitFlag = false;
    },
    // 编辑 常用意见
    editCommit: function (rowData) {
      this.submitCommentsFlag2 = true;
      this.editAddTitle = '编辑常用意见'
      this.commentInfo = rowData;
      this.editCommitFlag = true;
    },
    // 删除 常用意见
    deleteUseComment: function (opinionId) {
      var _that = this;
      confirmMsg('确定要删除该意见吗？：', '', function () {
        request('', {
          // url: 'http://106.52.77.101:8083/aplanmis-front/rest/comment/deleteUserOpinion/'+opinionId,
          url: ctx + 'rest/comment/deleteUserOpinion/' + opinionId,
          type: 'DELETE'
        }, function (data) {
          if (data.success) {
            _that.$message({
              message: data.message ? data.message : '删除成功',
              type: 'success'
            });
            _that.getCommitsList();
          } else {
            _that.$message({
              message: data.message ? data.message : '删除失败',
              type: 'error'
            });
          }
        }, function (msg) {
          _that.$message({
            message: msg.message ? msg.message : '删除失败',
            type: 'error'
          });
        })
      }, function () {
      }, '确定', '取消', 'warning', true)

    },
    // 保存 常用意见
    updateComment: function () {
      var url = '', type = '', param = {};
      var _that = this;
      if (_that.editCommitFlag) {
        // url = 'http://106.52.77.101:8083/aplanmis-front/rest/comment/editUserOpinion'
        url = ctx + 'rest/comment/editUserOpinion'
        type = 'put';
        param = {
          opinionContent: _that.commentInfo.opinionContent,
          opinionId: _that.commentInfo.opinionId,
          sortNo: _that.commentInfo.sortNo
        }
      } else {
        // url = 'http://106.52.77.101:8083/aplanmis-front/rest/comment/saveUserOpinion';
        url = ctx + 'rest/comment/saveUserOpinion'
        type = 'POST';
        param = {
          message: _that.commentInfo.opinionContent,
          sortNo: _that.commentInfo.sortNo
        }
      }
      request('', {
        url: url,
        type: type,
        data: param
      }, function (data) {
        if (data.success) {
          _that.$message({
            message: data.message ? data.message : '保存成功',
            type: 'success'
          });
          _that.submitCommentsFlag2 = false;
          _that.getCommitsList();
        } else {
          _that.$message({
            message: data.message ? data.message : '保存失败',
            type: 'error'
          });
        }
      }, function (msg) {
        _that.$message({
          message: msg.message ? msg.message : '保存失败',
          type: 'error'
        });
      })
    },


    getSingleMenuBadge: function (e) {
      var _that = this;
      _that.$set(e, 'isLoading', true);
      request('opus-admin', {
        url: ctx + e.menuCountUrl,
        type: 'get',
      }, function (data) {
        _that.$set(e, 'isLoading', false);
        if (data) {
          var count = 0;
          if (typeof (data.success) !== "undefined") {
            if (data.success) {
              count = data.content.total;
            }
          } else if (data.total) {
            count = data.total;
          } else {
            count = data;
          }
          e.subCount = count;
        }
      }, function (msg) {
        _that.$set(e, 'isLoading', false);
        _that.$message({
          message: '服务请求失败',
          type: 'error'
        });
      });
    },
    //获取门户标题及logo url
    initPortal: function () {
      var _that = this;
      request('opus-front', {
        url: ctx + 'opus/front/config',
        type: 'get',
      }, function (data) {
        if (data.success) {
          _that.portalTitle = data.content.title;
          if (_that.portalTitle != null)
            $("title").html(_that.portalTitle);
          _that.portalLogoUrl = data.content.logoUrl;
        }
      }, function (msg) {
        alertMsg('', '服务请求失败', '关闭', 'error', true);
      });
    },
    // 获取未读公告
    getCountAoaMsgRangeForMyReceiveUnReaded: function () {
      var _that = this;
      request('opus-admin', {
        url: ctx + 'rest/aoa/notice/content/getCountAoaNoticeContent',
        type: 'post',
        data: {businessFlag: 'busiTypeDefault'}
      }, function (data) {
        _that.noticeCount = data.content;
      });
    },
    // 获取用户登陆信息
    getUserIndo: function () {
      var _that = this;
      request('opus-admin', {
        url: ctx + 'opus/front/om/users/currOpusLoginUser',
        // url: '../../../../../static/agcloud/framework/ui-schemes/third-level-protal/js/user_1.json',
        type: 'get',
      }, function (data) {
        if (data.success) {
          _that.orgList = data.content.orgs || [];
          var orgList = _that.orgList;
          if (orgList && orgList.length) {
            _that.fOrgInfo.shortName = orgList[0].orgSeq;
            _that.fOrgInfo.orgName = orgList[0].orgName;
          }
          _that.loginName = data.content.user.loginName;
          _that.userName = data.content.user.userName;
          _that.userId = data.content.user.userId;
          _that.topOrgId = data.content.currentOrgId
          _that.getHeaderData(); // 获取头部菜单
          _that.getUserAllInfo(data.content.user.loginName);
          _that.getLogoutUrls();
        }
      }, function (msg) {
        alertMsg('', '服务请求失败', '关闭', 'error', true);
      });
    },
    // 获取登录用户所有信息
    getUserAllInfo: function (loginName) {
      var _that = this;
      request('agx', {
        // url: '../../../../../static/agcloud/framework/ui-schemes/third-level-protal/js/user_2.json',
        url: ctx + 'opus/front/om/users',
        type: 'get',
        data: {loginName: loginName}
      }, function (data) {
        if (data.success) {
          _that.userEmail = data.content.userEmail;
          _that.userSex = data.content.userSex;
          _that.userData = data.content;
          if (_that.userData.userAssignDate) {
            var userAssignDate = formatDate(new Date(_that.userData.userAssignDate), 'yyyy-MM-dd');
            _that.userData.userAssignDate = userAssignDate;
          }
          _that.forceHint = (data.content.enableStrongRemind == 1);
          // 未读消息
          _that.getUnReadMsgCount();
          setInterval(function () {
            _that.getUnReadMsgCount();
          }, _that.msgIntervalTime * 1000);
        }
      }, function (msg) {
        alertMsg('', '服务请求失败', '关闭', 'error', true);
      });
    },
    // 获取未读消息个数
    getUnReadMsgCount: function () {
      var _that = this;
      request('', {
        url: ctx + 'rest/aoa/msg/range/getCountAoaMsgRangeForMyReceiveUnReaded',
        type: 'post',
      }, function (data) {
        _that.messgeCount = data.content;
        if (_that.forceHint && _that.messgeCount > 0) {
          _that.getMsgList();
        }
        if (_that.messgeCount == 0) {
          _that.todoIndex = 0;
          _that.urgeIndex = 0;
          _that.todoMsgList = [];
          _that.urgeMsgList = [];
        }
      });
    },
    // 判定是否为待办消息
    judgeIsTodoMsg: function (o) {
      return o.contentSimpleTitle == this.TODOMENUTEXT;
    },
    // 判定是否为主办消息
    judgeIsMainMsg: function (o) {
      return o.contentSimpleTitle == this.MAINMENUTEXT;
    },
    // 判定是否为催办消息
    judgeIsUrgeMsg: function (o) {
      return o.jumpMode == 'iframe';
    },
    // 判定是否为协办消息
    judgeIsUnmainMsg: function(o){
      return o.contentSimpleTitle == this.UNMAINMENUTEXT;
    },
    // 获取所有消息数据，过滤未读信息并且分类
    getMsgList: function () {
      var vm = this;
      request('', {
        url: ctx + 'rest/aoa/msg/range/getPageAoaMsgRangeForMyReceive',
        type: 'post',
      }, function (res) {
        if (res.content && res.content.rows) {
          var _list = [];
          res.content.rows.forEach(function (u) {
            if (u.isRead != '1') {
              _list.push(u);
            }
          });
          vm.messgeCount = _list.length;
          vm.msgList = _list;
          var todoList = [];
          var mainMsgList = [];
          var unmainMsgList = [];
          var urgeList = [];
          _list.forEach(function (u) {
            if (vm.judgeIsTodoMsg(u)) {
              // 待办数据
              if (vm.todoMsgIds.indexOf(u.rangeId) == -1) {
                todoList.push(u);
                vm.todoMsgIds.push(u.rangeId);
              }
            } else if (vm.judgeIsMainMsg(u)) {
              // 主办消息
              if (vm.mainMsgIds.indexOf(u.rangeId) == -1) {
                mainMsgList.push(u);
                vm.mainMsgIds.push(u.rangeId);
              }
            } else if (vm.judgeIsUnmainMsg(u)) {
              // 协办消息
              if (vm.unmainMsgIds.indexOf(u.rangeId) == -1) {
                unmainMsgList.push(u);
                vm.unmainMsgIds.push(u.rangeId);
              }
            } else if (vm.judgeIsUrgeMsg(u)) {
              // 催办数据
              if (vm.urgeMsgIds.indexOf(u.rangeId) == -1) {
                urgeList.push(u);
                vm.urgeMsgIds.push(u.rangeId);
              }
            }
          });
          var todoRangeId = vm.todoMsgList.length ? vm.todoMsgList[vm.todoIndex].rangeId : '';
          var mainRangeId = vm.mainMsgList.length ? vm.mainMsgList[vm.mainIndex].rangeId : '';
          var unmainRangeId = vm.unmainMsgList.length ? vm.unmainMsgList[vm.unmainIndex].rangeId : '';
          var urgeRangeId = vm.urgeMsgList.length ? vm.urgeMsgList[vm.urgeIndex].rangeId : '';
          vm.todoMsgList = todoList.concat(vm.todoMsgList);
          vm.mainMsgList = mainMsgList.concat(vm.mainMsgList);
          vm.unmainMsgList = unmainMsgList.concat(vm.unmainMsgList);
          vm.urgeMsgList = urgeList.concat(vm.urgeMsgList);
          var nowTodoRangeId = -1;
          var nowMainRangeId = -1;
          var nowUnmainRangeId = -1;
          var nowUrgeRangeId = -1;
          vm.todoMsgList.forEach(function (u, index) {
            if (u.rangeId == todoRangeId) {
              nowTodoRangeId = index;
            }
          });
          vm.mainMsgList.forEach(function (u, index) {
            if (u.rangeId == mainRangeId) {
              nowMainRangeId = index;
            }
          });
          vm.unmainMsgList.forEach(function (u, index) {
            if (u.rangeId == unmainRangeId) {
              nowUnmainRangeId = index;
            }
          });
          vm.urgeMsgList.forEach(function (u, index) {
            if (u.rangeId == urgeRangeId) {
              nowUrgeRangeId = index;
            }
          });
          if (nowTodoRangeId == -1) {
            nowTodoRangeId = 0;
          }
          if (nowMainRangeId == -1) {
            nowMainRangeId = 0;
          }
          if (nowUnmainRangeId == -1) {
            nowUnmainRangeId = 0;
          }
          if (nowUrgeRangeId == -1) {
            nowUrgeRangeId = 0;
          }
          vm.todoIndex = nowTodoRangeId;
          vm.mainIndex = nowMainRangeId;
          vm.unmainIndex = nowUnmainRangeId;
          vm.urgeIndex = nowUrgeRangeId;
        }
      });
    },
    // 子页面传递的信息
    onMessage: function (e) {
      var _that = this
      var data = e.data
      if (!data.vueDetected && data.id != undefined) {
        data.menuInnerUrl = e.origin + data.menuInnerUrl
        _that.addTab(e, data, data.id);
      }
    },
    // 点击新增顶部tab openFlag打开方式
    addTab: function (ev, data, activeTab, ind, openFlag) {
      if (ev) {
        ev.cancelBubble = true;
      }
      if (openFlag == 'win') {
        window.open(data.menuInnerUrl);
        return false;
      };
      if (!data.childrenList && (this.activeTabId.indexOf(data.id) == -1)) {
        this.activeTabData.push(data);
        this.activeTabIframe = data.menuId;
        this.menuAddActive();
        this.activeTabId.push(data.menuId);
      } else {
        this.activeTabIframe = data.menuId;
        this.menuAddActive();
      }
    },
    // 关闭tab
    closeActiveTab: function () {
      try {
        $('#tab-' + vm.activeTabIframe + ' .el-icon-close').trigger('click');
      } catch (e) { console.error(e) }
    },
    // 判断是否全屏
    checkFull: function () {
      var isFull = document.fullscreenEnabled || window.fullScreen || document.webkitIsFullScreen || document.msFullscreenEnabled;
      if (isFull === undefined) {
        isFull = false;
      }
      return isFull
    },
    // 获取菜单数据
    getHeaderData: function () {
      var _that = this;
      var props = {
        isTree: 'true',
        netName: '前端网络入口',
        tmnId: '1',
        topOrgId: _that.topOrgId,
        userId: _that.userId
      };
      var _that = this;
      request('opus-admin', {
        url: ctx + 'opus/front/om/users/user/' + _that.userId + '/allMenus',
        // url: '../../../../../static/agcloud/framework/ui-schemes/header-no-left/json/menu.json',
        type: 'get',
        data: props
      }, function (data) {
        if (data.content && data.content.length > 0) {
          _that.headerData = data.content;
          _that.setHeaderShow();
          _that.findTodoMenu();
          _that.handleInnerUrl(data.content);
          _that.activeTabData.push(_that.headerData[0]);
          _that.activeTabId.push(_that.headerData[0].menuId);
          _that.activeTabIframe = _that.headerData[0].menuId;
          _that.headerActive = _that.headerData[0].menuId;
        }
      }, function (msg) {
        alertMsg('', '服务请求失败', '关闭', 'error', true);
      });
    },
    // 给menuInnerUrl加上menuCode数据，方便刷新badge红点数据
    handleInnerUrl: function (arr) {
      var _this = this;
      arr.forEach(function (u) {
        if (u.openMenuCount && u.menuCountUrl) {
          var chart = '?';
          if (u.menuInnerUrl.split('?').length > 1) {
            chart = '&';
          }
          u.menuInnerUrl += (chart + 'refreshBadgeCode=' + u.menuCode);
        }
        if (u.childrenList && u.childrenList.length) {
          _this.handleInnerUrl(u.childrenList);
        }
      });
    },
    // 找到待办任务菜单数据
    findTodoMenu: function () {
      var obj = this.findMenuObj('menuName', this.TODOMENUTEXT);
      this.todoMenuObj = obj.o;
      this.todoMenuIndex = obj.index;
    },
    // key 字段名  val 字段值
    findMenuObj: function (key, val) {
      var o = {};
      var index = 0;
      var flag = false;
      this.headerData.forEach(function (u, i) {
        if (flag) return null;
        var cList = u.childrenList || [];
        cList.forEach(function (uu, ii) {
          if (flag) return null;
          var ccList = uu.childrenList || [];
          if (ccList.length) {
            ccList.forEach(function (uuu, iii) {
              if (uuu[key] === val) {
                flag = true;
                o = uuu;
                index = iii;
              }
            })
          } else if (uu[key] == val) {
            flag = true;
            o = uu;
            index = ii;
          }
        });
      });
      return {o: o, index: index}
    },
    // 获取登出地址
    getLogoutUrls: function () {
      var _that = this;
      request('opus-admin', {
        url: ctx + 'opus/front/om/users/listLogoutUrl',
        type: 'get',
        data: {
          netName: '前端网络入口',
          orgId: _that.topOrgId,
          userId: _that.userId
        }
      }, function (result) {
        if (result.success) {
          _that.logoutSrc = result.content;
        } else {
          _that.logoutSrc = [];
        }
      }, function (msg) {
        // 获取登出地址失败

      });
    },
    // 选中头部菜单回调函数
    headerChangeMenu: function (menu) {
      if (this.activeTabId.indexOf(menu.menuId) < 0) {
        this.activeTabData.push(menu);
        this.activeTabId.push(menu.menuId);
      }
      this.activeTabIframe = menu.menuId;
      this.headerActive = menu.menuId;
    },
    // 设置头部可展示菜单长度
    setHeaderShow: function () {
      var _that = this;
      var width = $('.protal-header .header-menu').width();
      if (_that.headerData !== null && _that.headerData.length > 0) {
        var count = parseInt(width / 180);
        if (count < _that.headerData.length && count > 0) {
          _that.showMenuMore = true;
          _that.menuCount = count;
        } else if (count < 0 || count == 0) {
          _that.showMenuMore = true;
          _that.menuCount = 0;
        } else {
          _that.showMenuMore = false;
          _that.menuCount = _that.headerData.length;
        }
      } else {
        _that.showMenuMore = false;
        _that.menuCount = _that.headerData.length;
      }
      _that.initMenuCount(_that.headerData, _that.menuCount)
    },
    // 重置头部菜单
    initMenuCount: function (eleLi, n) {
      if (eleLi) {
        this.headerDataShow = eleLi.slice(0, n);
        this.hideHeaderData = eleLi.slice(n)
      }
    },
    menuAddActive: function () {
      $('.protal-content-left .el-menu-item').removeClass('is-active');
      $('#' + this.activeTabIframe).addClass('is-active').siblings('.el-menu-item').removeClass('is-active');
    },
    displayMenuPopover: function () { // 隐藏tab操作窗口
      this.showTabOpt = false;
    },
    removeTab: function (targetName) { // 移除顶部tab
      var tabs = this.activeTabData;
      var activeName = this.activeTabIframe;
      var _that = this;
      this.showTabOpt = false;
      if (activeName === targetName) {
        tabs.forEach(function (tab, index) {
          if (tab.menuId === targetName) {
            var nextTab = tabs[index + 1] || tabs[index - 1];
            if (nextTab) {
              activeName = nextTab.menuId;
            }
          }
        });
      }
      _that.activeTabIframe = activeName;
      _that.headerActive = activeName;
      _that.menuAddActive();
      _that.activeTabData = tabs.filter(function (tab) {
        return tab.menuId !== targetName
      });
      _that.activeTabId = [];
      _that.activeTabData.forEach(function (e) {
        _that.activeTabId.push(e.menuId);
      });
    },
    changeTab: function () {  // tab点击事件
      var tabEle = $('.el-tabs__content .el-tab-pane');
      var tabEleLen = tabEle.length;
      var _that = this;
      _that.menuAddActive();
    },
    tabMouseRightClick: function (ev) { // 顶部tab 右击事件
      ev.cancelBubble = true;
      if (ev.path) {
        this.tabId = ev.path[0].id;
        this.tabKey = ev.path[0].id.split('tab-')[1];
      } else {
        this.tabId = ev.srcElement.id
        this.tabKey = ev.srcElement.id.split('tab-')[1];
      }
      if (!(this.tabId.indexOf('tab') > -1)) {
        return false;
      } else {
        this.showTabOpt = true;
        this.tabOptTop = ev.offsetY + 60;
        this.tabOptleft = ev.clientX + 5;
        this.activeTabIframe = this.tabKey;
        this.menuAddActive();
      }
    },
    refreshUrl: function () {
      var start = this.activeTabId.indexOf(this.tabKey);
      var temp = this.activeTabData.slice(start, start + 1);
      if (temp && temp.length > 0) {
        var menuInnerUrl = temp[0].menuInnerUrl
        var menuId = 'pane-' + temp[0].menuId;
        menuId && (document.getElementById(menuId).getElementsByTagName('iframe')[0].src = menuInnerUrl);
        vm.$message.success('刷新操作成功！')
      } else {
        vm.$message.error('刷新操作失败！该菜单暂无设置相应的url。')
      }
      this.showTabOpt = false;
    },
    closeOther: function () { // 移除其他顶部tab
      var start = this.activeTabId.indexOf(this.tabKey);
      this.activeTabId = this.activeTabId.slice(start, start + 1);
      this.activeTabData = this.activeTabData.slice(start, start + 1);
      this.showTabOpt = false;
    },
    closeLeft: function () { // 移除左边顶部tab
      var start = this.activeTabId.indexOf(this.tabKey);
      this.activeTabId = this.activeTabId.slice(start);
      this.activeTabData = this.activeTabData.slice(start);
      this.showTabOpt = false;
    },
    closeRight: function () { // 移除右边顶部tab
      var start = this.activeTabId.indexOf(this.tabKey);
      this.activeTabId = this.activeTabId.slice(0, start + 1);
      this.activeTabData = this.activeTabData.slice(0, start + 1);
      this.showTabOpt = false;
    },
  }
});
